/*
 * AnchorPoint.java
 * 
 * Created by demory on Mar 28, 2009, 12:30:43 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.network;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.fpdev.apps.cart.gui.map.Canvas;
import org.fpdev.apps.cart.gui.map.Drawable;
//import org.fpdev.apps.cart.network.BundleComparator.LineInfo;

/**
 *
 * @author demory
 */
public class AnchorPoint implements Drawable {

  private int id_;
  private Point2D.Double point_;

  private Set<Corridor> corridors_;

  //private Map<Integer, List<LineInfo>> bundles_;


  public AnchorPoint(int id, double x, double y) {
    id_ = id;
    point_ = new Point2D.Double(x,y);
    corridors_ = new HashSet<Corridor>();
  }

  public int getID() {
    return id_;
  }

  public void draw(Canvas canvas) {
    Graphics2D g2d = canvas.getGraphics2D();

    int gx = canvas.getCoordinates().xToScreen(point_.x);
    int gy = canvas.getCoordinates().yToScreen(point_.y);

    g2d.setColor(Color.BLACK);
    g2d.setStroke(new BasicStroke(2));

    g2d.drawLine(gx-4, gy, gx+4, gy);
    g2d.drawLine(gx, gy-4, gx, gy+4);

    g2d.drawString(""+id_, gx+2, gy+13);
  }

  public void drawHighlight(Canvas canvas) {
    Graphics2D g2d = canvas.getGraphics2D();

    int gx = canvas.getCoordinates().xToScreen(point_.x);
    int gy = canvas.getCoordinates().yToScreen(point_.y);

    g2d.setColor(Color.YELLOW);
    g2d.setStroke(new BasicStroke(6));

    g2d.drawLine(gx-6, gy, gx+6, gy);
    g2d.drawLine(gx, gy-6, gx, gy+6);
  }

  public double getX() { return point_.x; }

  public double getY() { return point_.y; }

  public void moveTo(double x, double y) {
    point_.x = x;
    point_.y = y;
  }

  public void moveBy(double dx, double dy) {
    point_.x += dx;
    point_.y += dy;
  }

  public void registerCorridor(Corridor c) {
    corridors_.add(c);
  }

  public void unregisterCorridor(Corridor c) {
    corridors_.remove(c);
  }

  public Collection<Corridor> getCorridors() {
    return corridors_;
  }

  public Point2D.Double getPoint2D() {
    return point_;
  }

  public String getXML() {
    return "<point id=\""+id_+"\" x=\""+point_.x+"\" y=\""+point_.y+"\" />\n";
  }



  /*public void initBundles() {
    bundles_ = new HashMap<Integer, List<LineInfo>>();
  }

  public void addToBundle(Corridor corr, LineInfo li) {
    bundles_.get(corr.getAngle(this)).add(li);
  }

  public void sortBundles() {

  }

  public int largestBundleSize() {
    int size = 0;
    for(List bundle : bundles_.values()) {
      size = Math.max(size, bundle.size());
    }
    return size;
  }*/

}
